package se.cefalo.ceti.service;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import se.cefalo.ceti.ical.UrlRetrieverService;

import java.io.IOException;
import java.net.URL;

/**
 * Created by IntelliJ IDEA.
 * User: kopo700
 * Date: Oct 30, 2006
 * Time: 2:49:55 PM
 * To change this template use File | Settings | File Templates.
 */
public class UrlRetrieverServiceImpl implements UrlRetrieverService {

    public String getContent(URL url) {
        HttpClient httpClient = new HttpClient(connectionManager);

        GetMethod getMethod = new GetMethod(url.toString());

        try {
            httpClient.executeMethod(getMethod);
            return getMethod.getResponseBodyAsString();
        } catch (IOException e) {
            throw new RuntimeException("Unable to retrieve " + url, e);
        }
    }


    public HttpConnectionManager getConnectionManager() {
        return connectionManager;
    }

    public void setConnectionManager(HttpConnectionManager connectionManager) {
        this.connectionManager = connectionManager;
    }

    HttpConnectionManager connectionManager;

}
